package services;

import domain.entities.NormalValuesType;
import domain.entities.NormalValuesTypeDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: vgonzalez
 * Date: 31/10/12
 * Time: 13:10
 * To change this template use File | Settings | File Templates.
 */
@Service
public class NormalValuesTypeService {
    private NormalValuesTypeDAO normalValuesTypeDAO;

    public NormalValuesTypeService() {
    }

    @Autowired
    public NormalValuesTypeService(NormalValuesTypeDAO normalValuesTypeDAO) {
        this.normalValuesTypeDAO = normalValuesTypeDAO;
    }

    public List<NormalValuesType> findAll(){
        List<NormalValuesType> types = normalValuesTypeDAO.findAll();
        Collections.sort(types);
        return types;
    }

    public NormalValuesType findbyId(Integer id){
        return normalValuesTypeDAO.findById(id);
    }

    public NormalValuesType findByDescripcion(String descripcion){
        return normalValuesTypeDAO.findByDescripcion(descripcion);
    }

    public void checkType(String descripcion){
        if (!descripcion.equals("") && !normalValuesTypeDAO.existByDescripcion(descripcion)){
            normalValuesTypeDAO.attachDirty(new NormalValuesType(descripcion));
        }
        return ;
    }
}
